"""
写添加任务页面的信息
"""
from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from selenium.webdriver.support.select import Select
class RwtjPage(BasePage):
    url = ("http://192.168.1.55/crm/index.php?m=task&a=add")
    zt_locator = (By.ID, "subject")
    fzr_locator = (By.ID, "owner_name")
    fzr_admin_locator = (By.CSS_SELECTOR, "#ta1 > span > input")
    fzr_adminsure_locator = (By.XPATH, "/html/body/div[7]/div[3]/div/button[1]")
    rwxgr_locator = (By.ID, "about_roles_name")
    rwxgr_admin_locator = (By.CSS_SELECTOR, "#ta1 > span > input")
    rwxgr_adminsure_locator = (By.XPATH, "/html/body/div[8]/div[3]/div/button[1]")

    xzxg_loctor = (By.XPATH, '//*[@id="select1"]')
    xzxg_kh_locator = (By.ID, "module_name")
    # 清楚数据定位表格
    tbody_locator = (By.XPATH, '//*[@id="datas"]')
    xzxg_khsure_locator = (By.XPATH, "/html/body/div[11]/div[3]/div/button[1]")

    zhuangtai_locator = (By.XPATH, "/html/body/div[5]/div[2]/div/form/table/tbody/tr[6]/td[2]/select")
    email_locator = (By.NAME, "email_alert")
    data_locator = (By.ID, "due_date")
    yxj_locator = (By.NAME, "priority")
    miaosu_locator = (By.CSS_SELECTOR, ".ke-edit-iframe")
    baocun_locator = (By.XPATH, "/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td[2]/input[1]")

    def zt_input(self,zhuti):
        """主题输入框"""
        self.driver.find_element(*self.zt_locator).send_keys(zhuti)
    def fzr_click(self):
        """点击负责人"""
        self.driver.find_element(*self.fzr_locator).click()
        self.driver.find_element(*self.fzr_admin_locator).click()
        self.driver.find_element(*self.fzr_adminsure_locator).click()

    def rwxgr_click(self):
        """点击任务相关人"""
        self.driver.find_element(*self.rwxgr_locator).click()
        self.driver.find_element(*self.rwxgr_admin_locator).click()
        self.driver.find_element(*self.rwxgr_adminsure_locator).click()

    def xzxg_click(self,name):
        """点击任务相关"""
        xzxg_locator = self.driver.find_element(*self.xzxg_loctor)
        select = Select(xzxg_locator)
        select.select_by_index(2)  # 选择相关为客户
        self.driver.find_element(*self.xzxg_kh_locator).click()
        tbody = self.driver.find_element(*self.tbody_locator)
        trs = tbody.find_elements(By.TAG_NAME, "tr")
        for i in trs:
            tds = i.find_elements(By.TAG_NAME, 'td')
            if tds[1].text == name:
                tds[0].find_element(By.CSS_SELECTOR, 'input[name="customer"]').click()
                break
        self.driver.find_element(*self.xzxg_khsure_locator).click()

    def zhuangtai_click(self):
        """状态选择框"""
        zhuangtai_locator = self.driver.find_element(*self.zhuangtai_locator)
        select = Select(zhuangtai_locator)
        select.select_by_index(2)  # 选择状态为进行中
    def email_click(self):
        """点击邮件发送"""
        self.driver.find_element(*self.email_locator).click()
    def data_input(self,day):
        """日期控件"""
        self.driver.find_element(*self.data_locator).send_keys(day)

    def yxj_click(self):
        """优先级选择框"""
        yxj_locator = self.driver.find_element(*self.yxj_locator)
        select = Select(yxj_locator)
        select.select_by_index(1)  # 选择优先级为普通
    def miaosu_input(self,content):
        """描述输入框"""
        self.driver.find_element(*self.miaosu_locator).send_keys(content)
    def baocun_click(self):
        """点击保存"""
        self.driver.find_element(*self.baocun_locator).click()

    def open(self):
        """打开页面地址"""
        self.driver.get(self.url)